{extend name="app/admin/view/base.html"/}

{block name="resources"}
{/block}

{block name="main"}
<table id="template_list" lay-filter="template_list"></table>

<!-- 工具栏操作 -->
<script type="text/html" id="operation">
	<div class="ns-table-btn">
		<a class="layui-btn" lay-event="delete">删除模板</a>
	</div>
</script>
{/block}

{block name="script"}
<script type="text/javascript">
	var table = new Table({
		elem: '#template_list',
		url: ns.url("wxoplatform://admin/oplatform/template"),
		parseData: function(res){ //res 即为原始返回的数据
		    return {
		      	"code": res.code, //解析接口状态
		      	"msg": res.message, //解析提示文本
		      	"count": res.data.length, //解析数据长度
		      	"data": res.data //解析数据列表
		    };
	  	},
		cols: [
			[
				{
					field: 'user_version',
					title: '版本号',
					width: '15%',
					unresize: 'false',
				}, {
					field: 'user_desc',
					title: '描述',
					width: '25%',
					unresize: 'false'
				},
				{
					field: 'template_id',
					title: 'TemplateId',
					width: '15%',
					unresize: 'false'
				},{
					field: 'create_time',
					title: '添加时间',
					width: '15%',
					unresize: 'false',
					templet: function(data) {
						return ns.time_to_date(data.create_time);
					}
				},
				{
					title: '操作',
					width: '10%',
					toolbar: '#operation',
					unresize: 'false'
				}
			]
		],
		page: false
	});

	/**
	 * 监听工具栏操作
	 */
	table.tool(function(obj) {
		var data = obj.data,
			event = obj.event;
		switch (event) {
			case 'delete': //基本信息
				$.ajax({
                    url: ns.url("wxoplatform://admin/oplatform/deletetemplate"),
                    data: {
                        template_id: data.template_id
                    },
                    dataType: 'JSON',
                    type: 'POST',
                    success: function(res) {
                        layer.msg(res.message);
                        if (res.code == 0) {
                            table.reload();
                        }
                    }
                });
				break;
		}
	});
</script>
{/block}